package com.trkj.service.lzs;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.trkj.dao.lzs.SocialAccountDao;
import com.trkj.dao.lzs.SocialLeixingDao;
import com.trkj.dao.lzs.SocialSecurityDao;
import com.trkj.pojo.ProjectTemplate;
import com.trkj.pojo.Recruitprocess;
import com.trkj.pojo.Salary;
import com.trkj.pojo.SalaryAccount;
import com.trkj.pojo.SocialAccount;
import com.trkj.pojo.SocialLeixing;
import com.trkj.pojo.SocialSecurity;
import com.trkj.service.ServiceException;
import com.trkj.vo.ShebaoVo;
import com.trkj.vo.payVO;
@Service
public class SocialSecurityService {
	@Autowired
	private  SocialSecurityDao SocialSecurityDao;
	@Autowired
    private  SocialLeixingDao SocialLeixingdao;
	@Autowired 
	private  SocialAccountDao  socialAccountdao;
	  //查询所有
		public  List<SocialSecurity>  SocialSecurityfindAll(){
		   return (List<SocialSecurity>) SocialSecurityDao.findAll();
		}
		
		//添加
		public void SocialSecuritytj(Timestamp securityCretordate ,Timestamp securityEnddate,String securityName,BigDecimal securityNumberEmployees,String securityPerson
				,String securityRemark,Timestamp securityStartdate,Timestamp securityUpdatedate) {
			try {
				SocialSecurity ab= new SocialSecurity();
				ab.setSecurityCretordate(securityCretordate);
				ab.setSecurityEnddate(securityEnddate);
				ab.setSecurityName(securityName);
				ab.setSecurityNumberEmployees(securityNumberEmployees);
				ab.setSecurityRemark(securityRemark);
				ab.setSecurityStartdate(securityStartdate);
				ab.setSecurityUpdatedate(securityUpdatedate);
				ab.setSecurityPerson(securityPerson);
				SocialSecurityDao.save(ab);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
		
		 //编辑  
	    public   void lzs_SocialSecurity( Long securityId,Timestamp securityCretordate ,Timestamp securityEnddate,String securityName,BigDecimal securityNumberEmployees,String securityPerson
				,String securityRemark,Timestamp securityStartdate,Timestamp securityUpdatedate) {
	    	 SocialSecurity edit =SocialSecurityDao.findOne(securityId);
	   	     edit.setSecurityCretordate(securityCretordate);
	   	     edit.setSecurityEnddate(securityEnddate);
		   	 edit.setSecurityName(securityName);
		   	 edit.setSecurityNumberEmployees(securityNumberEmployees);
		   	 edit.setSecurityPerson(securityPerson);
		   	 edit.setSecurityRemark(securityRemark);
		   	 edit.setSecurityStartdate(securityStartdate);
		   	 edit.setSecurityUpdatedate(securityUpdatedate);
		   	 
		   	SocialSecurityDao.save(edit);
	    }
	    
	    public SocialSecurity chun(Long securityId) {
	    	return SocialSecurityDao.findOne(securityId);

	    }
	  //模糊查询
	  		//根据姓名查找
	  		public  List<SocialSecurity> queryByName (String  text){

	  			return SocialSecurityDao.queryByName("%" + text + "%");
	  		}
	  		 //多表查询
	  		    public List<ShebaoVo> selcet_SalaryAccount(){
	  	 		List<ShebaoVo> vo = new ArrayList();
	  	 		List<Object[]> obj= SocialSecurityDao.find_pay();
	  	 		for (Object[] objects : obj) {
	  	 			ShebaoVo vof = new ShebaoVo();
	  	 			
	  	 			SocialSecurity s  = (SocialSecurity) objects[0];
	  	 			SocialAccount  p  = (SocialAccount) objects[1];
	  	 			SocialLeixing  w  = (SocialLeixing) objects[2];
	  	 			if(s!=null){
	  	 				vof.setSecurityId(s.getSecurityId());
	  	 			}
	  	 			if(p!=null){
	  	 				vof.setSblxId(p.getSocialId());
	  	 			}
	  	 			if(w!=null){
	  	 				vof.setSocialId(w.getSblxId());
	  	 			}
	  	 				
	  	 				vof.setSecurityRemark(s.getSecurityRemark());
	  	 				vof.setSecurityName(s.getSecurityName());
	  	 				vof.setSecurityUpdatedate(s.getSecurityUpdatedate());
	  	 				vof.setSecurityStartdate(s.getSecurityStartdate());
	  	 				vof.setSocialName(p.getSocialName());
	  	 				vof.setSecurityNumberEmployees(s.getSecurityNumberEmployees());
	  	 	              vo.add(vof);
	  	 		}
	  	 		return vo;
	  	 	}
	  	     
	  	     
	  	/* //多表增加
	  	     public void add_SalaryAccount(SocialSecurity s,Long socialId,Long sblxId){
	  	 		try {
	  	 			SocialLeixing p = SocialLeixingdao.findOne(sblxId);
	  	 		    SocialAccount re= socialAccountdao.findOne(socialId);
	  	 		 SocialSecurity sl = new SocialSecurity();
	  	 			sl.setSocialLeixing(p);
	  	 			System.out.println(p);
	  	 			System.out.println(re);
		  	 		sl.setSocialAccount(re);
	  	 			SocialSecurityDao.save(s);
	  	 		} catch (Exception e) {
	  	 			e.printStackTrace();
	  	 			throw new ServiceException(e);
	  	 		}
	  	 	}*/
	    
	  
		public List<ShebaoVo> selcet_social_table(){
			List<ShebaoVo> vo = new ArrayList();
			List<Object[]> obj= SocialSecurityDao.find_social_table();
			for (Object[] objects : obj) {
				ShebaoVo vof = new ShebaoVo();
				SocialSecurity s  = (SocialSecurity) objects[0];
				SocialAccount Soc  = (SocialAccount) objects[1];
				SocialLeixing  w  = (SocialLeixing) objects[2];
				if(Soc!=null){
					vof.setSocialId(Soc.getSocialId());
				}
			     	vof.setSblxId(w.getSblxId());
					vof.setSocialName(Soc.getSocialName());
					vof.setSecurityId(s.getSecurityId());
					vof.setSecurityName(s.getSecurityName());
					vof.setSecurityNumberEmployees(s.getSecurityNumberEmployees());
					vof.setSecurityStartdate(s.getSecurityStartdate());
		         	vof.setSecurityEnddate(s.getSecurityEnddate());
					vof.setSecurityRemark(s.getSecurityRemark());
					vo.add(vof);
			}
			
			return vo;
		}

		/**
		 * 新增
		 * @param s
		 */
	public void add_SocialSecurity(SocialSecurity Social,Long socialId ,Long sblxId){
			try {
				 SocialSecurity sl = new SocialSecurity();
				 sl.setSecurityEnddate(Social.getSecurityEnddate());
				 sl.setSecurityStartdate(Social.getSecurityStartdate());
				 sl.setSecurityName(Social.getSecurityName());
				 sl.setSecurityNumberEmployees(Social.getSecurityNumberEmployees());
				SocialAccount soc = socialAccountdao.findOne(socialId );
				SocialLeixing en =SocialLeixingdao.findOne(sblxId);
				sl.setSocialAccount(soc);
				sl.setSocialLeixing(en);
		
				SocialSecurityDao.save(sl);
			} catch (Exception e) {
				e.printStackTrace();
				throw new ServiceException(e);
			}
		}


}
